﻿using System;
using System.Data;


namespace DAL
{
    public static class DalExpenditure
    {
        private static readonly clsConnect Cls = new clsConnect();
        #region[Get-Data]
        public static DataTable GetExpenditure(string keywords)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@KEYWORDS", keywords);
            return Cls.GetData("sp_Expenditure_Get");
        }
        public static DataTable GetExpenditureEdit(int id)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@ID", id);
            return Cls.GetData("sp_Expenditure_Get_Edit");
        }
        public static DataTable GetExpenditureTotal(int id, int flag)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@Order_Buy_Id", id);
            return Cls.GetData("sp_Order_Buy_Total");
        }
        public static DataTable GetExpenditureReport(string keywords)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@KEYWORDS", keywords);
            return Cls.GetData("sp_ExpenditureReport_Get");
        }
        public static bool GetExpenditureCheck(EtExpenditure obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@Order_Buy_Id", obj.Order_Buy_Id);
            obj.Msg = Cls.ExecuteNonQueryOutput("sp_Expenditure_Check", "@Msg");
            return true;
        }
        public static bool GetExpenditureCheckAmout(EtExpenditure obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@Order_Buy_Id", obj.Order_Buy_Id);
            Cls.AddParameter("@AmountOutput",obj.Amount);
            Cls.AddParameter("@VoucherAmount", obj.VoucherAmount);
            obj.Msg = Cls.ExecuteNonQueryOutput("sp_Expenditure_Check_Amount", "@Msg");
            return true;
        }
        public static DataTable GetExpenditureTotal(int orderBuyId, float voucherAmount)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@Order_Buy_Id", orderBuyId);
            Cls.AddParameter("@VoucherAmount", voucherAmount);
            return Cls.GetData("sp_Expenditure");
        }
        public static DataTable GetExpenditureFillterDate(string dateBegin, string dateEnd)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@DateBegin", dateBegin);
            Cls.AddParameter("@EndBegin", dateEnd);
            return Cls.GetData("sp_Expenditure_FillterDate");
        }
        public static DataTable GetExpenditureReportFillterDate(string dateBegin, string dateEnd)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@DateBegin", dateBegin);
            Cls.AddParameter("@EndBegin", dateEnd);
            return Cls.GetData("sp_ExpenditureReport_FillterDate");
        }
        #endregion

        #region[Insert-Update-Delete]
        public static bool InsertExpenditure(EtExpenditure obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@ExpenditureCode", obj.ExpenditureCode);
            Cls.AddParameter("@ExpenditureDate", obj.ExpenditureDate);
            Cls.AddParameter("@IDReceiptReason", obj.IDReceiptReason);
            Cls.AddParameter("@PayerRecipientCode", obj.PayerRecipientCode);
            Cls.AddParameter("@Order_Buy_Id", obj.Order_Buy_Id);
            Cls.AddParameter("@VoucherFile", obj.VoucherFile);
            Cls.AddParameter("@VoucherAmount", obj.VoucherAmount);
            Cls.AddParameter("@Amount", obj.Amount);
            Cls.AddParameter("@Amount_Remain", obj.Amount_Remain);
            Cls.AddParameter("@Note", obj.Note);
            return Cls.ExecuteNonQuery("sp_Expenditure_Insert");
        }
        public static bool UpdateExpenditure(EtExpenditure obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@ID", obj.ID);
            Cls.AddParameter("@ExpenditureCode", obj.ExpenditureCode);
            Cls.AddParameter("@ExpenditureDate", obj.ExpenditureDate);
            Cls.AddParameter("@IDReceiptReason", obj.IDReceiptReason);
            Cls.AddParameter("@PayerRecipientCode", obj.PayerRecipientCode);
            Cls.AddParameter("@Order_Buy_Id", obj.Order_Buy_Id);
            Cls.AddParameter("@VoucherFile", obj.VoucherFile);
            Cls.AddParameter("@VoucherAmount", obj.VoucherAmount);
            Cls.AddParameter("@Amount", obj.Amount);
            Cls.AddParameter("@Note", obj.Note);
            obj.Msg = Cls.ExecuteNonQueryOutput("sp_Expenditure_Update", "@Msg");
            return true;
        }
        public static bool DeleteExpenditure(EtExpenditure obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@ID", obj.ID);
            obj.Msg = Cls.ExecuteNonQueryOutput("sp_Expenditure_Delete", "@Msg");
            return true;
        }
        #endregion
    }
    public class EtExpenditure
    {
        public int ID { get; set; }
        public string ExpenditureCode { get; set; }
        public DateTime ExpenditureDate { get; set; }
        public int IDReceiptReason { get; set; }
        public int PayerRecipientCode { get; set; }
        public int ? Order_Buy_Id { get; set; }
        public string VoucherFile { get; set; }
        public float? VoucherAmount { get; set; }
        public float? Amount { get; set; }
        public string Note { get; set; }
        public int Msg { get; set; }
        public int Flag { get; set; }
        public float ? Amount_Remain { get; set; }
    }
}
